package com.sx.pipeline.repos.http.res;


import com.sx.pipeline.utils.Cn2Spell;
/**
 * author : zhouyouqiang
 * e-mail : 1638473898@qq.com
 * date   : 2022/6/10 10:21
 * desc   :
 * version: 1.0
 */
public class ContactUserVo implements Comparable<ContactUserVo> {
    private String userName; // 姓名
    private String avatar; //头像
    private Integer userUnitId; //用户id
    private String pinyin; // 姓名对应的拼音
    private String firstLetter; // 拼音的首字母
    public int userType;
    public boolean hasGroup;
    public ContactUserVo() {
    }

    public ContactUserVo(Integer userId,String name,String avatar) {
        this.userName = name;
        this.userUnitId=userId;
        this.avatar=avatar;
        pinyin = Cn2Spell.getPinYin(name); // 根据姓名获取拼音
        firstLetter = pinyin.substring(0, 1).toUpperCase(); // 获取拼音首字母并转成大写
        if (!firstLetter.matches("[A-Z]")) { // 如果不在A-Z中则默认为“#”
            firstLetter = "#";
        }
    }

    public Integer getUserUnitId() {
        return userUnitId;
    }

    public void setUserUnitId(Integer userUnitId) {
        this.userUnitId = userUnitId;
    }

    public String getAvatar() {
        return avatar;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPinyin() {
        return pinyin;
    }

    public void setPinyin(String pinyin) {
        this.pinyin = pinyin;
    }

    public String getFirstLetter() {
        return firstLetter;
    }

    public void setFirstLetter(String firstLetter) {
        this.firstLetter = firstLetter;
    }

    @Override
    public int compareTo(ContactUserVo another) {
        if (firstLetter.equals("#") && !another.getFirstLetter().equals("#")) {
            return 1;
        } else if (!firstLetter.equals("#") && another.getFirstLetter().equals("#")){
            return -1;
        } else {
            return pinyin.compareToIgnoreCase(another.getPinyin());
        }
    }
}
